package com.xxl.job.executor.service.jobhandler;

import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.executor.my.service.RangeLandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <h3>xxl-job</h3>
 * <p>养猪管理系统定时任务</p>
 *
 * @author : 来朋
 * @date : 2020-12-19 16:19
 **/
@Component
public class RangeLandXxlJob {

    @Autowired
    private RangeLandService rangeLandService;

    @XxlJob("syncLiveStockToEs")
    public void syncLiveStockToEs(){
        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        Date nowDate=new Date();
        XxlJobHelper.log(dateFormat.format(nowDate)+"养猪管理系统批次存栏信息校对任务开启：\n");
        rangeLandService.adjustBathStock();
        XxlJobHelper.log(dateFormat.format(nowDate)+"养猪管理系统批次存栏信息校对任务结束：\n");
    }

    /**
     * 处理养猪系统查询库的错误信息
     */
    @XxlJob("syncLiveStockOfRangeQueryDB")
    public void syncLiveStockOfRangeQueryDB(){
        try {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
            Date nowDate = new Date();
            XxlJobHelper.log(dateFormat.format(nowDate) + "养猪管理系统批次存栏信息校对任务开启：\n");
            rangeLandService.handleBatchErrorLogOfQuerydb();
            nowDate = new Date();
            XxlJobHelper.log(dateFormat.format(nowDate) + "养猪管理系统批次存栏信息校对任务结束：\n");
        } catch (Exception err){
            XxlJobHelper.log("处理批次存栏时发生异常:\n" +err.getMessage()+ "\n");
        }
    }









}
